/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.entity.merchant;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;
import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.neusoft.lohas.common.persistence.IdEntity;

/**
 * 送货员Entity
 * @author Jackie.Liu
 * @version 2014-11-03
 */
@Entity
@Table(name = "ivm_delivery_member")
@DynamicInsert @DynamicUpdate
public class DeliveryMember extends IdEntity<DeliveryMember> {

	private static final long serialVersionUID = 1L;
	private String name; 	// 姓名
	private String phone;	//手机号
	private int type;		//人员类型（1送货员   2采购员）
	private Merchant merchant; //商户信息
	
	private List<DeliveryIndent> deliveryIndent = Lists.newArrayList();    //送货员订单列表

	public DeliveryMember() {
		super();
	}

	public DeliveryMember(String id){
		this();
		this.id = id;
	}
	
	@Length(min=1, max=200)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	@ManyToOne
	@JoinColumn(name="merchant_id")
	@NotFound(action = NotFoundAction.IGNORE)
	@JsonIgnore
	@NotNull(message="所属商户信息不能为空")
	public Merchant getMerchant() {
		return merchant;
	}

	public void setMerchant(Merchant merchant) {
		this.merchant = merchant;
	}

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "deliveryMember")
	@Where(clause="del_flag='"+DEL_FLAG_NORMAL+"'")
	@OrderBy(value="indentId")
	@NotFound(action = NotFoundAction.IGNORE)
	public List<DeliveryIndent> getDeliveryIndent() {
		return deliveryIndent;
	}

	public void setDeliveryIndent(List<DeliveryIndent> deliveryIndent) {
		this.deliveryIndent = deliveryIndent;
	}
	
	public static final int TYPE_DELIVERY = 1;
	public static final int TYPE_PURCHASE = 2;
}


